package com.happyrecyclingstation.mapper;

import com.github.pagehelper.Page;
import com.happyrecyclingstation.dto.AdminUserQueryDto;
import com.happyrecyclingstation.entity.User;
import com.happyrecyclingstation.vo.AdminUserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {
    /**
     * 根据手机号查询用户
     * @param phone
     * @return
     */
    @Select("select * from lzxm_user where phone = #{phone}")
    User selectByPhone(String phone);

    /**
     * 注册
     * @param user
     */
    @Insert("insert into lzxm_user(username, phone, password, user_type, create_time, update_time) values " +
            "(#{username},#{phone},#{password},#{userType},#{createTime},#{updateTime})")
    void insert(User user);

    /**
     * 根据id查询公司id
     * @param id
     * @return
     */
    @Select("select company_id from lzxm_user where id = #{id}")
    Integer selectCompanyId(Integer id);

    /**
     * 管理查询用户列表
     * @param queryParam
     * @return
     */
    Page<AdminUserVO> selectUserList(AdminUserQueryDto queryParam);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("select * from lzxm_user where id = #{id}")
    User selectById(Integer id);

    /**
     * 启用或禁用用户
     * @param user
     */
    void update(User user);

    /**
     * 查询hr是否关联了企业
     * @param id
     */
    @Select("select company_id from lzxm_user where id = #{id}")
    Integer isRelated(Integer id);
}
